# Maintainer: Tobias Powalowski <tpowa@archlinux.org>

pkgname=(archboot-linux-firmware)
pkgver=20210919.d526e04
pkgrel=5
pkgdesc="Firmware files for archboot creation"
url="https://git.kernel.org/?p=linux/kernel/git/firmware/linux-firmware.git;a=summary"
license=('GPL2' 'GPL3' 'custom')
arch=('any')
makedepends=('linux-firmware' 'kmod' 'linux' 'tar')
conflicts=('linux-firmware')
options=(!strip)

package() {
  cd /lib/modules/*
  # get firmware files from modules
  for i in $(find -name '*.ko.zst');do
    FIRMWARE="$FIRMWARE $(echo $(modinfo -F firmware $(pwd)/$i))"
  done
  mkdir -p ${pkgdir}/usr
  for i in $(echo $FIRMWARE);do
  [[ -e /lib/firmware/$i ]] &&  tar -C / -clpf - lib/firmware/$i | tar -C ${pkgdir}/usr -vxlspf -
  done
  # fix symlinks
  tar -C / -clpf - lib/firmware/cypress | tar -C ${pkgdir}/usr -vxlspf -
  tar -C / -clpf - lib/firmware/cxgb4/t4fw-1.26.0.0.bin | tar -C ${pkgdir}/usr -vxlspf -
  tar -C / -clpf - lib/firmware/cxgb4/t5fw-1.26.0.0.bin | tar -C ${pkgdir}/usr -vxlspf -
  tar -C / -clpf - lib/firmware/cxgb4/t6fw-1.26.0.0.bin | tar -C ${pkgdir}/usr -vxlspf -
  tar -C / -clpf - lib/firmware/netronome/nic | tar -C ${pkgdir}/usr -vxlspf -
  tar -C / -clpf - lib/firmware/intel/ice/ddp/ice-1.3.26.0.pkg | tar -C ${pkgdir}/usr -vxlspf -
  tar -C / -clpf - lib/firmware/rtl_bt/rtl8821c_config.bin | tar -C ${pkgdir}/usr -vxlspf -
  # compress firmware with xz, wait for mkinitcpio support to be implemented
  # #FS 72263
  # find ${pkgdir}/usr -type f -execdir xz -C crc32 -z {} \+ 
  # add licenses
  mkdir -p ${pkgdir}/usr/share/licenses/archboot-linux-firmware
  tar -C /usr/share/licenses/linux-firmware -clpf - ./ | tar -C ${pkgdir}/usr/share/licenses/archboot-linux-firmware -vxlspf -
}
# vim:set sw=2 et:
